<script type="text/javascript" language="JavaScript">
<!--

function hideDiv(d) {
	getE(d).style.display = "none";
}

function showDiv(d) {
	getE(d).style.display = "block";
}

function toggleDiv(d) {
	if(getE(d).style.display == "none") { getE(d).style.display = "block"; }
	else { getE(d).style.display = "none"; }
}

function centerWin(d) {
	x = getE(d);
	vpWidth=self.innerWidth;
	vpHeight=self.innerHeight;
	dialogWidth=x.offsetWidth;
	dialogHeight=x.offsetHeight;
	dialogTop = (vpHeight/2) - (dialogHeight/2);
	dialogLeft = (vpWidth/2) - (dialogWidth/2);
	x.style.top =dialogTop+"px";
	x.style.left =dialogLeft+"px";
}

function showIsAltWin(charName, charID) {
	fillIsAltWin(charName, charID);
	showDiv('isAltWin');
	centerWin('isAltWin');
	getE('isAltSearch').focus();
}

function fillIsAltWin(charName, charID) {
	getE('isAltWin').innerHTML = '<table class="cleanTable"><tr>'
		+ '<td width="100%"><form action="isAlt.php" method="POST">'
		+ charName + ' is an alt of <input type="text" id="isAltSearch" name="altOf">'
		+ '<input type="hidden" name="name" value="'+ charName +'">'
		+ '<input type="hidden" name="charID" value="'+ charID +'"></form></td>'

		+ '<td width="0%"><a href="javascript:hideDiv(\'isAltWin\')">'
		+ '<img src="images/greenx.jpg"></a></td>'
		+ '</tr></table>';
}

function hideIsAltWin() {
	showDiv('isAltWin');
}

function recenterIsAltWin() {
	centerWin('isAltWin');
}

function showFlagWin(charName, main, charID, afk, afkText, tz, carrier, dread, investigate, posgunner, notes, redirect, posd, exempt, legacy, probation) {
	fillFlagWin(charName, main, charID, afk, afkText, tz, carrier, dread, investigate, posgunner, notes, redirect, posd, exempt, legacy, probation);
	showDiv('flagWin');
	centerWin('flagWin');
}

function fillFlagWin(charName, main, charID, afk, afkText, tz, carrier, dread, investigate, posgunner, notes, redirect, posd, exempt, legacy, probation) {
	if (tz == 1) tzEuro = 'SELECTED'; else tzEuro = '';
	if (tz == 2) tzAmer = 'SELECTED'; else tzAmer = '';
	if (tz == 3) tzOceanic = 'SELECTED'; else tzOceanic = '';
	
	if (carrier == 1) carrier1 = 'SELECTED'; else carrier1 = '';
	if (carrier == 2) carrier2 = 'SELECTED'; else carrier2 = '';
	if (carrier == 3) carrier3 = 'SELECTED'; else carrier3 = '';
	if (carrier == 4) carrier4 = 'SELECTED'; else carrier4 = '';
	
	if (dread == 1) dread1 = 'SELECTED'; else dread1 = '';
	if (dread == 2) dread2 = 'SELECTED'; else dread2 = '';
	if (dread == 3) dread3 = 'SELECTED'; else dread3 = '';
	if (dread == 4) dread4 = 'SELECTED'; else dread4 = '';
	//inserting the quotes in the correct places
	notes = notes.replace(/c39c/g,'\'');
	notes = notes.replace(/c34c/g,'\"');
	charName = charName.replace(/c39c/,'\'');
	charName = charName.replace(/c34c/,'\"');
	
	
	getE('flagWin').innerHTML = '<form action="addFlags.php" method="POST"><table class="cleanTable"><tr>'
		+ '<td width="100%">' + charName + ' is...<br></td>'
		+ '<td width="0%" style="text-align: right;"><a href="javascript:hideDiv(\'flagWin\')">'
		+ '<img src="images/greenx.jpg"></a></td>'
		
		+ '<tr><td style="padding-left: 10px;">'
		+ '<input type="hidden" name="main2" value="'+ main +'">'
		+ '<input type="hidden" name="main" value="'+ charName +'">'
		+ '<input type="hidden" name="charID" value="'+ charID +'">'
		+ '<input type="hidden" name="redirect" value="'+ redirect +'">'
		+ '<input type="checkbox" id="afk" name="afk" value="true" '+ afk +'>AFK because <input id="afkText" type="text" name="afkText" size="31" value="' + afkText + '"><br>'
		+ '<input type="checkbox" name="investigate" value="true" '+ investigate +'>Investigate<br><br>'
		+ '<table class="cleanTable">'
		+ '<tr><td colspan=2><input type="checkbox" name="posd" value="true" '+ posd +'>POS Duties</td>'
		+ '<td colspan=2><input type="checkbox" name="exempt" value="true" '+ exempt +'>Exempt/Officer</td></tr>'
		+ '<tr><td colspan=2><input type="checkbox" name="legacy" value="true" '+ legacy +'>Legacy Member</td></tr>'
		+ '<tr><td colspan=3><input type="checkbox" name="probation" value="true" '+ probation +'>Member on Probation</td></tr>'
		+ '<tr><td colspan=2><input type="checkbox" name="posgunner" value="true" '+ posgunner +'>POS Gunner</td><td>Timezone:</td><td><select name="tz"><option value="0">Unknown</option><option value="1" '+ tzEuro +'>European</option><option value="2" '+ tzAmer +'>American</option><option value="3" '+ tzOceanic +'>Oceanic</option></select></td></tr>'
		+ '<tr><td>Carrier:</td><td><select name="carrier"><option value="0">None</option><option value="1" '+ carrier1 +'>Archon</option><option value="2" '+ carrier2 +'>Chimera</option><option value="3" '+ carrier3 +'>Thanatos</option><option value="4" '+ carrier4 +'>Nidhoggur</option></select></td>'
		+ '<td>Dread:</td><td><select name="dread"><option value="0">None</option><option value="1" '+ dread1 +'>Revelation</option><option value="2" '+ dread2 +'>Phoenix</option><option value="3" '+ dread3 +'>Moros</option><option value="4" '+ dread4 +'>Naglfar</option></select></td></tr>'
		+ '</table><br>'
		+ 'Notes:<br><textarea name="notes" rows="7" cols="38">' + notes + '</textarea>'
		+ '</td><td style="vertical-align: bottom;"><input type="submit" value="Go"></td></tr></table></form>';
}

function hideFlagWin() {
	showDiv('flagWin');
}

function recenterFlagWin() {
	centerWin('flagWin');
}

function getE(x) {
	return document.getElementById(x);
}

function selectAllText() {
	this.select();
}

function selectAFKText() {
	getE('afkText').select();
}

function selectCustomText() {
	getE('customText').select();
}

function installListeners() {
	window.addEventListener('resize', recenterIsAltWin, false);
	window.addEventListener('resize', recenterFlagWin, false);
	getE('search').addEventListener('click', selectAllText, false);
}

window.addEventListener('load', installListeners, false);

//-->
</script>
